package com.zxy.config.util;

import org.apache.shiro.crypto.hash.Md5Hash;

import java.util.Random;

/**
 * @Author Zxy
 * @Date 2021/1/8 17:38
 * @Version 1.0
 */
public class SaltUtils {

    /**
     * 生成salt的静态方法
     *
     * @param n 盐值的位数
     * @return 生成好的盐
     */
    public static String getSalt(int n) {
        char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()".toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char aChar = chars[new Random().nextInt(chars.length)];
            sb.append(aChar);
        }
        return sb.toString();
    }

}
